﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HCFramework.Master.Control
{
    public partial class UserInfo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitDisplay();
        }

        private void InitDisplay()
        {
            if (C.UserController.IsLogin())
            {
                PlaceHolderChuaDangNhap.Visible = false;
                PlaceHolderDaDangNhap.Visible = true;

                HyperLinkMyAccount.Text = C.UserController.GetUsername();
                HyperLinkMyAccount.NavigateUrl = "~/User/MyAccount/MyAccount.aspx";
            }
            else
            {
                PlaceHolderChuaDangNhap.Visible = true;
                PlaceHolderDaDangNhap.Visible = false;
            }
        }

        protected void LinkButtonLogout_Click(object sender, EventArgs e)
        {
            C.UserController.Logout();
            Response.Redirect(Request.Url.AbsoluteUri);
        }

        protected void LinkButtonLogin_Click(object sender, EventArgs e)
        {
            string continueUrl = HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri);
            if (!String.IsNullOrEmpty(Request["returnURL"])) continueUrl = HttpUtility.UrlEncode(Request["returnURL"]);
            Response.Redirect("~/User/Login/Login.aspx?returnURL=" + continueUrl);
        }

        protected void LinkButtonRegister_Click(object sender, EventArgs e)
        {
            string continueUrl = HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri);
            if (!String.IsNullOrEmpty(Request["returnURL"])) continueUrl = HttpUtility.UrlEncode(Request["returnURL"]);
            Response.Redirect("~/User/Register/Register.aspx?returnURL=" + continueUrl);
        }

    }
}